package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.MoodTopicInfoMapper;
import com.cdks.wuxiu.api.model.dto.MoodTopicInfoDTO;
import com.cdks.wuxiu.entity.mysql.MoodTopicInfo;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * 心情主题信息 服务实现类
 */
@Slf4j
@Service
public class MoodTopicInfoServiceImpl extends ServiceImpl<MoodTopicInfoMapper, MoodTopicInfo> implements MoodTopicInfoService {

    @Override
    public List<MoodTopicInfoDTO> getList(long userId, int type, int groupId, int page) {
        List<MoodTopicInfoDTO> topicInfoList  = null;

        switch (type)
        {
            case Constant.MOOD_LIST_ALL:
            {
                topicInfoList  = baseMapper.getListAll(userId, groupId, page * Constant.LIST_PAGE_SIZE, Constant.LIST_PAGE_SIZE);
                break;
            }

            case Constant.MOOD_LIST_FANS:
            {
                topicInfoList  = baseMapper.getListFans(userId, groupId, page * Constant.LIST_PAGE_SIZE, Constant.LIST_PAGE_SIZE);
                break;
            }

            case Constant.MOOD_LIST_MINE:
            {
                topicInfoList  = baseMapper.getListMine(userId, groupId, page * Constant.LIST_PAGE_SIZE, Constant.LIST_PAGE_SIZE);
                break;
            }
        }

        return topicInfoList;
    }

    @Override
    public MoodTopicInfoDTO getDetailById(long topicId) {
        return baseMapper.getDetailById(topicId);
    }

    @Override
    public List<MoodTopicInfo> getListByUser(long userId, int page, int isSelf) {
        return baseMapper.getListByUser(page * Constant.LIST_PAGE_SIZE, Constant.LIST_PAGE_SIZE, userId, isSelf);
    }

    @Override
    public int addReplyCount(long topicId) {
        int ret  = baseMapper.addReplyCount(topicId);
        if (ret == 1)
        {
            return 0;
        }

        log.error("更新评论次数失败：ret = " + ret);

        return -1;
    }
}
